package com.guigu.www.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.www.pojo.DesignProcedureDetails;
import com.guigu.www.pojo.File;
import com.guigu.www.pojo.MProcedure;
import com.guigu.www.pojo.PageVo;
import com.guigu.www.service.MProcedureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.MalformedParameterizedTypeException;
import java.util.HashMap;
import java.util.Map;

@RestController
public class MProcedureController {
    @Autowired
    MProcedureService mProcedureService;
    //生产工序表


    //查询
    @RequestMapping("mplist.action")
    public PageVo<MProcedure> querymplistbypage(MProcedure mProcedure,
                                              @RequestParam(value = "pagenum", defaultValue = "1") int pagenum,
                                              @RequestParam(value = "pagesize", defaultValue = "5") int pagesize) {


        Page<MProcedure> page = mProcedureService.page(new Page<MProcedure>(pagenum, pagesize));


        PageVo<MProcedure> pageVo = new PageVo<MProcedure>();

        pageVo.setRows(page.getRecords());
        pageVo.setTotal(page.getTotal());

        return pageVo;
    }

    //生产工序表添加
    @PostMapping("addmplist.action")
    public Map addmplist(MProcedure mProcedure) {

        Map map = new HashMap();

        boolean f = mProcedureService.save(mProcedure);

        if(f){
            //  map.put("code","0");
            map.put("msg","添加成功");
        }else {
            // map.put("code","0");
            map.put("msg","添加失败");
        }

        return map;
    }



    //生产工序表修改
    @PutMapping("updatemProceduretql.action")
    public Map updatedmProceduretql(@RequestBody MProcedure mProcedure){
        System.out.println(mProcedure);
        boolean f=mProcedureService.updateById(mProcedure);
        Map map=new HashMap();
        if(f){
            map.put("msg","修改成功");
        }else {
            map.put("msg","修改失败");
        }
        return map;
    }

    //查询当前工序的物料
    @RequestMapping("/queryByMProcedureModule.action")
    public MProcedure queryByMProcedureModule(int id){
        return  mProcedureService.queryByMProcedureModule(id);
    }

    @RequestMapping("/updaterealamount.action")
    public Map updaterealamount(int id,int amount){
        Map map=new HashMap();
        //判断
        map.put("msg","交接登记失败");
        //调用方法
        boolean f=mProcedureService.updaterealamount(id,amount);
        if(f){
            map.put("msg","交接登记成功,等待审核");
        }
        return  map;

    }



}
